<?php
namespace App\Pay\Config;

/**
 * Class Config
 * @package App\Pay\Config
 */
class Config
{
    /**
     * 微信商户id  qq商户id  支付宝应用id
     * @var string
     */
    private $mchId = '';

    /**
     * 微信商户key qq商户key
     * @var string
     */
    private $mchKey = '';

    /**
     * 微信公众号appid
     * @var string
     */
    private $mpAppid = '';

    /**
     * 微信公众号 secret
     * @var string
     */
    private $mpSecret = '';

    /**
     * 支付宝公钥
     * @var string
     */
    private $publicKey = '';

    /**
     * 支付宝商户私钥
     * @var string
     */
    private $privateKey = '';

    /**
     * 异步通知地址
     * @var string
     */
    private $notifyUrl = '';

    /**
     * 同步回跳地址
     * @var string
     */
    private $returnUrl = '';

    /**
     * 支付模式
     * @var string
     */
    private $mode = '';

    /**
     * Config constructor.
     * @param $config
     */
    public function __construct($config = [])
    {
        $this->mchId = $config['mch_id'] ?? '';
        $this->mchKey = $config['mch_key'] ?? '';
        $this->mpAppid = $config['mp_appid'] ?? '';
        $this->mpSecret = $config['mp_secret'] ?? '';
        $this->publicKey = $config['public_key'] ?? '';
        $this->privateKey = $config['private_key'] ?? '';
        $this->notifyUrl = $config['notify_url'] ?? '';
        $this->returnUrl = $config['return_url'] ?? '';
        $this->mode = $config['mode'] ?? '';
    }

    public function get($name, $default = null)
    {
        $var = $this->camelize($name, '_');
        return empty($this->{$var}) ? $default : $this->{$var};
    }

    private function camelize($uncamelized_words,$separator='_')
    {
        $uncamelized_words = $separator. str_replace($separator, " ", strtolower($uncamelized_words));
        return ltrim(str_replace(" ", "", ucwords($uncamelized_words)), $separator );
    }
}
